package model;

import controller.MessageController;

import java.io.IOException;

public class HealMedicine extends Medicine{
    private int add_hp;
    private int add_nl;
    private int add_jl;

    public HealMedicine(HealMedicine m) {
        super(m.getNum(), m.getName(), m.getType(), m.getDesc(),m.getLocation());
        this.add_hp = m.getAdd_hp();
        this.add_nl = m.getAdd_nl();
        this.add_jl = m.getAdd_jl();
    }

    public HealMedicine(int num, String name, String type, String desc, int add_hp, int add_nl, int add_jl,String location) {
        super(num,name,type,desc,location);
        this.add_hp = add_hp;
        this.add_nl = add_nl;
        this.add_jl = add_jl;
    }

    public int getAdd_hp() {
        return add_hp;
    }
    public void setAdd_hp(int add_hp) {
        this.add_hp = add_hp;
    }
    public int getAdd_nl() {
        return add_nl;
    }
    public void setAdd_nl(int add_nl) {
        this.add_nl = add_nl;
    }
    public int getAdd_jl() {
        return add_jl;
    }
    public void setAdd_jl(int add_jl) {
        this.add_jl = add_jl;
    }

    public void use(Player player) throws IOException {
        if(this.have()){
            if(player.getHp()==player.getMax_hp()&&player.getNl()==player.getMax_nl()&&player.getJl()==player.getMax_jl()){
                MessageController.showToPlayer(player,"您的状态无需回复");
            }else {
                this.setNum(this.getNum()-1);
                player.setHp(Math.min(player.getHp()+this.getAdd_hp(),player.getMax_hp()));
                player.setJl(Math.min(player.getJl()+this.getAdd_jl(),player.getMax_jl()));
                player.setNl(Math.min(player.getNl()+this.getAdd_nl(),player.getMax_nl()));
                MessageController.showToPlayer(player,"使用成功。\n");
                MessageController.showToPlayer(player,player.getdesc());
            }
        } else{
            MessageController.showToPlayer(player,"您没有此物品。");
        }
    }

    @Override
    public String getDesc() {
        String tmp="";
        tmp+="名称:"+getName()+"\n";
        tmp+="数量:"+getNum()+"\n";
        tmp+="类型:"+getType()+"\n";
        if(add_hp>0){
            tmp+="hp:+"+getAdd_hp()+"\n";
        }
        if(add_nl>0){
            tmp+="nl:+"+getAdd_nl()+"\n";
        }
        if(add_jl>0){
            tmp+="jl:+"+getAdd_jl()+"\n";
        }
        tmp+="物品描述:"+desc+"\n";
        return tmp;
    }

}
